import UIKit
import Flutter
import UserNotifications

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    
    var eventChannel: LCTySmartHomeTool?
    
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
      
      // 1.获取FlutterViewController
      let controller: FlutterViewController = window.rootViewController as! FlutterViewController;
  //    // 2.创建FlutterMethodChannel
  //    let channel = FlutterMethodChannel(name: "coderwhy.com/battery", binaryMessenger: controller.binaryMessenger);
  //
  //    // 3.监听channel调用方法
  //    channel.setMethodCallHandler { (call: FlutterMethodCall, result: @escaping FlutterResult) in
  //
  //        let tool = LCTySmartHomeTool()
  //        tool.handle(call: call, result: result)
  //
  //    }
      
      eventChannel = LCTySmartHomeTool(messenger: controller.binaryMessenger)
      
      
    GeneratedPluginRegistrant.register(with: self)
      
      // 设置通知
      if #available(iOS 10.0, *) {
        UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate
      }
      
      
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
    
    override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
//        print(error)
        NSLog("PUSH registration failed: \(error)")
    }
}
